package com.zzyl.controller;

import cn.hutool.core.util.BooleanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.impl.NursingProjectServiceImpl;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController{

    @Resource
    NursingProjectServiceImpl nursingProjectService;



    @ApiOperation("分页条件查询护理项目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "护理项目名称"),
            @ApiImplicitParam(name = "status", value = "项目状态（0：禁用，1：启用）"),
            @ApiImplicitParam(name = "pageNum", value = "页数", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", defaultValue = "10", required = true)
    })
    @GetMapping
    public ResponseResult<NursingProjectVo> query(@RequestParam(required = false) String name,@RequestParam(required = false) Integer status,
                                @RequestParam Integer pageNum,@RequestParam Integer pageSize){
        PageResponse<NursingProjectVo> query = nursingProjectService.query(name, status, pageNum, pageSize);
        return success(query);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDTO 护理项目数据传输对象
     * @return 操作结果
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nursingProjectDTO", value = "护理项目数据传输对象")
    })
    public ResponseResult<Void> add(@RequestBody NursingProjectDto nursingProjectDTO) {
        Long userIdByName = getUserIdByName();
        nursingProjectDTO.setCreateBy(userIdByName);
        nursingProjectDTO.setUpdateBy(userIdByName);
        Boolean result = this.nursingProjectService.add(nursingProjectDTO);
        if (BooleanUtil.isTrue(result)) {
            return ResponseResult.success();
        }
        return ResponseResult.error();
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> selectById(@PathVariable("id")Integer id){
        return nursingProjectService.selectById(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult deleteById(@PathVariable("id")Integer id){

        return nursingProjectService.deleteById(id);
    }

    @PutMapping("{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult updateStatus(@PathVariable("id")Integer id,@PathVariable("status")Integer status){
        return nursingProjectService.updateStatus(id,status);
    }

    @PutMapping
    @ApiOperation("修改信息")
    public ResponseResult updateInfo(@RequestBody NursingProjectDto nursingProjectDTO){
        Long userIdByName = getUserIdByName();
        nursingProjectDTO.setUpdateBy(userIdByName);
        return nursingProjectService.updateInfo(nursingProjectDTO);
    }
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult listAll(){
        return nursingProjectService.listAll();
    }

}
